﻿using MachineVision.API.Models;
using MachineVision.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace MachineVision.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    //[Authorize(Roles = "Admin")]//
    public class MenuController : ControllerBase
    {
        private readonly ILogger<MenuController> logger;
        private readonly IMenuService mService;

        public MenuController(ILogger<MenuController> logger, IMenuService mService)
        {
            this.logger = logger;
            this.mService = mService;
        }
        // GET: api/<MenuController>
        [HttpGet]
        public ApiResult Get()
        {
            ApiResult result = new ApiResult();
            //TODO
            if (User.HasClaim(s => s.Type.Contains("role")))
            {

                //TODO  测试获取角色   后期查询数据时 封装出去 返回roleid或者权限内id
                if (!User.IsInRole("User"))
                {
                    result.code = 0;
                    result.msg = "Test权限错误";

                    return result;
                }
                result.data = mService.GetDatas();
                //result.data = new List<menudata> {
                //    new menudata { name = "视频组", icon = "layui-icon-home", pages = new List<menudata>()
                //        {
                //            new menudata

                //            {
                //                name = "视频监控(标准流)", icon = "layui-icon-console", pageUrl = "videos/basicvideo.html",
                //            },
                //            new menudata
                //            {
                //                name = "视频监控(UIKIT)", icon = "layui-icon-console", pageUrl = "videos/uikitvideo.html",
                //            }
                //        }
                //    },
                //        new menudata { name = "各项监测", icon = "layui-icon-time", pageUrl = "", pages = new List<menudata>()
                //        {
                //            new menudata { name = "温度监测", icon = "layui-icon-light", pageUrl = "temperature/templist.html", }
                //        }
                //    },
                //        new menudata  { name = "测试", icon = "layui-icon-transfer", pageUrl = "", pages = new List<menudata>()
                //        {
                //            new menudata { name = "测试页面",pageUrl = "test/test.html", }
                //        }
                //    },
                //};
                return result;
            }

            result.code = 0;
            result.msg = "权限错误";
            
            return result;
        }

        //// GET api/<MenuController>/5
        //[HttpGet("{id}")]
        //public string Get(int id)
        //{
        //    return "value";
        //}

        //// POST api/<MenuController>
        //[HttpPost]
        //public void Post([FromBody] string value)
        //{
        //}

        //// PUT api/<MenuController>/5
        //[HttpPut("{id}")]
        //public void Put(int id, [FromBody] string value)
        //{
        //}

        //// DELETE api/<MenuController>/5
        //[HttpDelete("{id}")]
        //public void Delete(int id)
        //{
        //}
    }
    public class menudata
    {
        public string name { get; set; }
        public string icon { get; set; }
        public string pageUrl { get; set; }
        public List<menudata> pages { get; set; }
    }
}
